package com.rgp.internalcommon.dto;

import com.rgp.internalcommon.common.CommonStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-10 21:40
 */
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Data
public class ResponseResult<T> {
    private Integer code;
    private String message;
    private T data;

    public static ResponseResult success(){
        return new ResponseResult()
                .setCode(CommonStatusEnum.SUCCESS.getCode())
                .setMessage(CommonStatusEnum.SUCCESS.getMessage());
    }

    public static <T> ResponseResult success(T data){
        return new ResponseResult()
                .setCode(CommonStatusEnum.SUCCESS.getCode())
                .setMessage(CommonStatusEnum.SUCCESS.getMessage())
                .setData(data);
    }

    // 未知异常
    public static ResponseResult error(){
        return new ResponseResult()
                .setCode(CommonStatusEnum.ERROR.getCode())
                .setMessage(CommonStatusEnum.ERROR.getMessage());
    }

    //失败
    public static ResponseResult fail(){
        return new ResponseResult()
                .setCode(CommonStatusEnum.FAIL.getCode())
                .setMessage(CommonStatusEnum.FAIL.getMessage());
    }

    public static ResponseResult fail(CommonStatusEnum commonStatusEnum){
        return new ResponseResult()
                .setCode(commonStatusEnum.getCode())
                .setMessage(commonStatusEnum.getMessage());
    }

    public static <T> ResponseResult fail(CommonStatusEnum commonStatusEnum,T data){
        return new ResponseResult()
                .setCode(commonStatusEnum.getCode())
                .setMessage(commonStatusEnum.getMessage())
                .setData(data);
    }
}
